package net.oschina.bilbodai.common.beanutil.bean.code;

import net.oschina.bilbodai.common.beanutil.bean.core.PropertyDumpInfo;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Type;

import static org.objectweb.asm.Opcodes.INVOKEVIRTUAL;

/**
 * @author daimao  Date: 16/5/28 Time: 下午4:34
 * @version $Id$
 */
public class EnumToStringApplier extends DumpOverrideAwareApplier {

    public EnumToStringApplier(PropertyDumpInfo dumpInfo) {
        super(dumpInfo);
    }

    @Override
    protected void loadSrcCastPropertyOntoStack(MethodVisitor mv) {
        loadSrcCastPropertyOntoStack0(mv);
    }

    @Override
    protected void doApply(MethodVisitor mv) {
        loadTargetCastOntoStack0(mv);

        loadSrcCastPropertyOntoStack(mv);
        mv.visitMethodInsn(INVOKEVIRTUAL, Type.getInternalName(dumpInfo.getSrcField().getType()),
                "name", "()Ljava/lang/String;", false);
        invokeTargetPropertySetter0(mv);
    }

}